<?php

/**
 * MVM_MALL 网上商店系统 积分支付
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-06-26 $
 * $Id: integral.class.php  www.mvmmall.com$
 * ---------------------------------------------
*/
if(!defined('MVMMALL')){
    exit('Access Denied');
}
//插件的代码必须和文件名保持一致
$payment['integral']['name']    = '积分支付';
//描述
$payment['integral']['desc']    = '积分支付';
//支付费用
$payment['integral']['pay_fee'] = '0%';
// 是否支持在线支付
$spayment['integral']['online']  = 0;
//否支持货到付款
$payment['integral']['cod']     = 0;
//申请地址
$payment['integral']['reg']     = '0';
//版权信息
$payment['integral']['license']  = '版权所有www.mvmmall.com';
//接口需要的参数
$payment['integral']['cfg'] =array(
        array('name' => 'point_nums', 'value' => '10','label'=>'1金额可换算积分'),
    );
    
class integral
{
    var $cfg;
    
    function  integral($cfg = array())
    {
        foreach ($cfg AS $key=>$val)
        {
            $this->cfg[$val['name']] = $val['value'];
        }
    }
    
/*提交支付请求*/
function pay_send($sn,$amount)
{
    $lang = $GLOBALS[lang];
    if($GLOBALS['m_check_id']==null) {
        echo "<script language='javascript'>alert('$lang[login_please]');</script>";
        echo '<meta http-equiv="refresh" content="0;url=logging.php?action=login&referer=cart.php?action=list"/>';
        exit;
    }
    $m_now_time=time();
    $v_url = MVMMALL_DIR."/respond.php?code=".basename(__FILE__, '.class.php');;		///支付结果返回地址
    $result="
				<FORM  name=re METHOD=post ACTION='$v_url' target='_blank'>
				<input type='hidden' name='sn' value='$sn'>
				<input type='hidden' name='amount' value='$amount'>
				<input type='submit' value='$lang[point_pay]'>
				</FORM>
				";
    $result=trim($result);
    return   $result;
}
/**
 * 提交返回处理*
 */
function pay_receive()
{
	$sn     = strip_tags(trim($_REQUEST['sn']));//定单号
	$amount = floatval(trim($_REQUEST['amount']));//金额
	$lang   = $GLOBALS[lang];
	!$GLOBALS['m_check_id'] && show_msg('login_please',"logging.php?action=login&referer=".dreferer());
	$m_now_time=time();
	$list = $GLOBALS['db']->get_one("SELECT member_point,member_id FROM `{$GLOBALS['tablepre']}member_table` WHERE member_id = '$GLOBALS[m_check_id]'");
	$point_nums = round(($amount*$this->cfg['point_nums']),2); //可换得多少积分
	$list['member_point']< $point_nums && show_msg('point_err','member.php?action=point');
	$order_list = order_info($sn);
	if ($order_list['order_amount']==floatval($amount)){
		/* 改变订单状态*/
		change_order($sn);
		$query = "INSERT INTO `{$GLOBALS['tablepre']}point_table` SET
                      point_id       = '$GLOBALS[m_check_id]',
                      point_add      = '-$point_nums',
                      point_reason   = '$lang[point_pay]:$sn',
                      point_category = '1',
                      modify_id      = '$GLOBALS[m_check_id]',
                      modify_ip      = '$GLOBALS[m_user_ip]',
                      register_date  = '$m_now_time',
                      approval_date  = '$m_now_time'";
		$GLOBALS[db]->query($query);
		//更新会员预存款内容信息
		$GLOBALS[db]->query("UPDATE  `{$GLOBALS['tablepre']}member_table` SET  member_point = member_point - '$point_nums' WHERE member_id = '$GLOBALS[m_check_id]'");
		//更新session状态
		$_SESSION['user']['mvm_sess_point']=($list['member_point']-$point_nums);
		return true;
	}else {
		//和定单数据库不一致
		return false;
	}
}
}